package com.woniuxy.yogaapp.mapper;

import com.woniuxy.yogaapp.pojo.Attention;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 操作 Attention表
 */
public interface AttentionMapper {

    /**
     * 插入关注信息
     * @param attention
     * @return
     */
    @Insert("insert into attention(me,other,aname,aimage,roles) values (#{me},#{other},#{aname},#{aimage},#{roles})")
    int addAttention(Attention attention);

    /**
     * 查询是me是否已经关注other
     * @param meUid
     * @param otherUid
     * @return
     */
    @Select("select aid from attention where me = #{param1} and other = #{param2}")
    Integer isAttentionOkByUid(Integer meUid, Integer otherUid);

    /**
     * 取消对other的关注
     * @param attention
     * @return
     */
    @Delete("delete from attention where me = #{me} and other = #{other};")
    int cancelAttention(Attention attention);

    /**
     * 查询我所有关注的对象
     *
     * @param uid
     * @return
     */
    @Select("select * from attention where me = #{uid}")
    @Results({
            @Result(id = true, property = "aid", column = "aid"),
            @Result(property = "other",column = "other"),
            @Result(property = "chats",column = "other",many =
            @Many(select = "com.woniuxy.yogaapp.mapper.ChatMapper.findSayChatByUid"))
    })
    List<Attention> findAttentionsByUid(Integer uid);

}
